from sqlalchemy import Column, String, INTEGER

from sqlConfig import Base


class User(Base):
    __tablename__ = 'user'  # 指定表名字为 user
    # 主键id, 自增, varchar类型 限制12 不为空
    userId = Column(String(12), primary_key=True)
    # userName字段 varchar类型 限制12 不为空
    userName = Column(String(12), nullable=False)
    # password字段, varchar类型 限制12 不为空
    password = Column(String(12), nullable=False)

    phone_number = Column(String(12), nullable=False)

    dormitoryId = Column(String(12))

    isAdmin = Column(INTEGER(), nullable=False)

    def __init__(self, userId, userName, passWord, phone_number, dormitoryId, isAdmin):
        self.userId = userId
        self.userName = userName
        self.password = passWord
        self.phone_number = phone_number
        self.dormitoryId = dormitoryId
        self.isAdmin = isAdmin

    def __int__(self, user):
        self.userId = user.userId
        self.userName = user.userName
        self.password = user.passWord
        self.phone_number = user.phone_number
        self.dormitoryId = user.dormitoryId
        self.isAdmin = user.isAdmin
